<template>
  <view>
    <view class="content">
      <jyf-parser :html="content" ref="article" :tag-style="tagStyle"></jyf-parser>
    </view>
  </view>
</template>

<script>
import {HTTP_REQUEST_URL} from "@/config/app";

let sysHeight = uni.getSystemInfoSync().statusBarHeight;
import parser from '@/components/jyf-parser/jyf-parser';
import { getUserAgreement } from '@/api/user.js';
export default {
  components: {
    'jyf-parser': parser
  },
  data() {
    return {
      tagStyle: {
        img: 'width:100%;display:block;',
        table: 'width:100%',
        video: 'width:100%'
      },
      content: ``,
      sysHeight: sysHeight || 0,
      type: '',
      list:{
        esign_sdk3:{
          title:'租赁服务合同',
          url:HTTP_REQUEST_URL+'/uploads/contract/esign_sdk3_tempalte.pdf'
        },
        esign_auth:{
          title:'认证服务协议',
          url:HTTP_REQUEST_URL+'/uploads/contract/esign_auth_agreement.pdf'
        },
        esign_digital:{
          title:'数字证书服务协议',
          url:HTTP_REQUEST_URL+'/uploads/contract/esign_digital_cert_agreement.pdf'
        },
        esign_privacy:{
          title:'隐私政策',
          url:HTTP_REQUEST_URL+'/uploads/contract/esign_privacy_policy.pdf'
        }
      }
    };
  },

  onLoad(options) {
    this.type = options.type;
    uni.showLoading({
      title: '合同加载中...'
    })
    // 修改标题
    uni.setNavigationBarTitle({
      title: this.list[this.type].title
    });

    uni.downloadFile({
      url:this.list[this.type].url,
      success: (res) => {
        if (res.statusCode === 200) {
          uni.openDocument({
            filePath: res.tempFilePath,
            fileType: 'pdf',
            success:()=>{
              uni.hideLoading()
              uni.navigateBack()
            },
            fail: (err) => {
              this.$util.Tips({ title: '合同加载失败'})
            }
          });
        }
      },
      fail: (err) => {
        uni.hideLoading()
        this.$util.Tips({ title: '合同加载失败'})
      }
    });


  },
  mounted() {},
  methods: {
    goBack() {
      uni.navigateBack({
        delta: 1
      });
    }
  }
};
</script>

<style scoped lang="scss">
page {
  background-color: #fff;
}
.content {
  padding: 0 30rpx 40rpx 30rpx;
}
.sys-head {
  position: fixed;
  width: 100%;
  background-color: #fff;
  top: 0;
  left: 0;
  z-index: 9;
  .sys-title {
    height: 43px;
    line-height: 43px;
    text-align: center;
    position: relative;
    .iconfont {
      position: absolute;
      left: 20rpx;
    }
  }
}
</style>
